using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace UFrame
{
    /// <summary>
    /// 特效复制窗口
    /// </summary>
    public class EffectCopySelectWindow : EditorWindow
    {
        private string[] skillList;
        private int curSelect;
        private System.Action<string> onApplyAction;

        public void Init(List<string> skills, System.Action<string> onApply)
        {
            skillList = skills.ToArray();
            onApplyAction = onApply;
        }

        void OnGUI()
        {
            if (skillList == null || skillList.Length == 0)
            {
                return;
            }

            curSelect = EditorGUILayout.Popup(curSelect, skillList);

            if (GUILayout.Button("套用"))
            {
                if (onApplyAction != null)
                {
                    if (skillList != null && skillList.Length > curSelect && curSelect >= 0)
                    {
                        onApplyAction(skillList[curSelect]);
                    }

                    onApplyAction = null;
                }

                Close();
            }
        }
    }
}